package com.bibrApp.difu.actvity.others;

import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.bibrApp.difu.R;
import com.bibrApp.difu.utils.UIUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

public class QuestionAdapter extends BaseQuickAdapter<QuestionBean, BaseViewHolder> {

    int selectIndex = -1;

    public QuestionAdapter() {
        super(R.layout.item_question, new ArrayList<>());
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, QuestionBean item) {

        helper.setText(R.id.item_answer, item.getAnswer());
        TextView textView = helper.getView(R.id.item_question);
        textView.setText(item.getQuestion());
        if (getData().indexOf(item) == selectIndex) {
            UIUtils.setDrawableRight(textView, R.drawable.ic_expand_more_black_24dp);
            helper.setGone(R.id.item_answer, true);
        } else {
            UIUtils.setDrawableRight(textView, R.drawable.ic_chevron_right_black_24dp);
            helper.setGone(R.id.item_answer, false);
        }

    }

    public void setSelect(int select) {
        if(this.selectIndex == select){
            this.selectIndex = -1;
        }else {
            this.selectIndex = select;
        }

        notifyDataSetChanged();
    }

    public void setDatas(List<QuestionBean> datas, int select) {
        this.selectIndex = select;
        setNewData(datas);
    }
}
